<?php
/**
 * Yotaku Shop - yshop
 * @author Creatint<creatint@163.com>
 * @copyright www.yotaku.cn 2016
 */
namespace Admin\Controller;
use Think\Page;
class ConfigController extends AdminController {
    public function index(){
        $Config = D("Config");
        $configs = $Config->getConfig();

        $this->assign('info',array('id'=>0));
        trace($configs,'configs');
        $this->assign('configs',$configs);
        $this->display();
    }

    public function group(){
        $Config = D("Config");
        $configs = $Config->getConfig();

        $this->assign('group',C('CONFIG_GROUP'));
        $this->assign('group_id',I('get.group',0));
        $this->assign('configs',$configs);


        $this->display();
    }

    public function update(){
        if(IS_POST){
            $Config =   D("Config");
            $data = $_POST['config'];
            $data = array_filter($data);
            trace($_POST,'post');
            $status = true;
            foreach($data as $v){
                if($res = $Config->update($v)){
                }else{
                    $status = false;
                }
            }
            if($status){
                S("DB_CONFIG",null);
                $this->success($res['id']?'修改成功':'新增成功');
            }else{
                $this->error($Config->getError());
            }

        }
    }
    public function edit($id){
        $Config = D("Config");
        $info = $Config->getDetail($id);
        $this->assign('info',$info);
        $this->display();
    }
    
    public function add(){
        $this->assign('info',array('id'=>0));

        $this->assign('pannel_title','新增配置');
        $this->display();
    }
    public function delete(){
        $Config =   D("Config");
        $id = array_unique((array)I('id',0));
        $res = $Config->del($id);
        if($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败 '.$Config->getError());
        }
    }


}